﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Pibby.Core;
using Pibby.Core.IO;

namespace Pibby.Controls
{
	public class MediaListView : SortableListView
	{
		public MediaListView()
			: base()
		{
		}

		public void Configure()
		{
			this.View = View.Details;

			this.Columns.Add("File", 100, HorizontalAlignment.Left);
			this.Columns.Add("Size", 100, HorizontalAlignment.Right);
			this.Columns.Add("Date", 100, HorizontalAlignment.Right);
			this.Columns.Add("Folder", 100, HorizontalAlignment.Left);

			this.RefreshColumnSpacing();
	
			this.FullRowSelect = true;
		}

		public void RefreshColumnSpacing()
		{
			int columnWidth = this.ClientSize.Width / 10;

			if (this.Columns.Count == 4)
			{
				this.Columns[0].Width = columnWidth * 2;
				this.Columns[1].Width = columnWidth;
				this.Columns[2].Width = columnWidth;
				this.Columns[3].Width = columnWidth * 6;
			}
		}

		public void UpdateContent(IFileCollection collection)
		{
			this.BeginUpdate();

			foreach (IFile f in collection)
			{
				//this.Items.Add(new PodcastListViewItem(p));
			}

			this.EndUpdate();
		}

		public void RefreshContent(IFileCollection collection)
		{
			this.Items.Clear();

			this.UpdateContent(collection);

			this.SortByColumn(1, SortOrder.Descending);
		}
	}
}

